package com.example.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
    //用户自定义配置项
    //value注解的使用一定是@value("${xxx}")这样才能够将key对应的value读取到这个变量中,
    //否则就将原字符串读取到这个变量中
    @Value("${myKey.key}")
    private String myKey;

    //读取系统的配置项
    @Value("${server.port}")
    private Integer port;

    private static Logger logger = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private Student student;

    @Autowired
    private MyDBType myDBType;

    @Autowired
    private People people;

    @Value("${people.name}")
    private String name;
    @Value("${people.sex}")
    private String sex;
    @Value("${people.age}")
    private int age;

    @Autowired
    private MyDBList myDBList;

    @Value("${mystring.str1}")
    private String str1;

    @Value("${mystring.str2}")
    private String str2;

    @Value("${mystring.str3}")
    private String str3;

    @RequestMapping("/str")
    public void str(){
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
    }

    @RequestMapping("/say")
    public String say() {
        return "姓名 : " + name
                +" 性别 : " + sex
                + " 年龄 : " + age;
    }

    @RequestMapping("/people")
    public String sayPeople() {
        return "人的名字 : "+people.getName()
                + " 人的性别 : " + people.getSex()
                + " 人的年龄 : " + people.getAge();
    }

    @RequestMapping("/myDB")
    public String myDB() {
        return "数据库(0) : " + myDBList.getDbname().get(0)
        + " myDB size : " + myDBList.getDbname().size();
    }

    @RequestMapping("/hi")
    public String sayHi() {
        logger.trace("hi trace~~~");
        logger.debug("hi debug~~~");
        logger.info ("hi info ~~~");
        logger.warn ("hi warn ~~~");
        logger.error("hi error~~~");
        return "";
    }
}